/**
 * Created by zhourh on 2018/6/12.
 *
 * 给定一个二进制数组， 计算其中最大连续1的个数。

 示例 1:

 输入: [1,1,0,1,1,1]
 输出: 3
 解释: 开头的两位和最后的三位都是连续1，所以最大连续1的个数是 3.
 */
public class MaxConsecutiveOnes {

    public static void main(String[] args) {
        System.out.println(new MaxConsecutiveOnes().findMaxConsecutiveOnes(new int[]{1,1,0,1,1,1}));
    }

    public int findMaxConsecutiveOnes(int[] nums) {
        int maxOnes = 0;
        if (nums == null || nums.length == 0) {
            return maxOnes;
        }

        int ones = 0;
        for (int num : nums) {
            ones = (num == 1 ? ones + 1 : 0);
            if (ones > maxOnes) {
                maxOnes = ones;
            }
        }

        return maxOnes;
    }
}
